// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   QNA2B4.java

package org.quickserver.net.GB268753QN.control;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.dykj.fireFighting.common.core.utils.UUIDUtils;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.model.report.Gb26875State;
import com.dykj.fireFighting.web.service.Gb26875StateService;
import com.dykj.fireFighting.web.utils.SpringUtil;
import org.quickserver.net.model.GB268753QN;
import org.quickserver.net.model.GBServerData;
import org.quickserver.net.server.ClientHandler;
import org.quickserver.util.data.dataProcessing;
import org.quickserver.util.state.QNA2B2State;
import org.quickserver.util.state.QNA2B4State;

public class QNA2B4
{
    private static RedisService redisCache= SpringUtil.getBean(RedisService.class);
    private static Gb26875StateService gb26875StateService=SpringUtil.getBean(Gb26875StateService.class);
    public QNA2B4()
    {
    }

    public static GB268753QN QNA2B4OBJ(ClientHandler handler, String strs[])
    {
        GBServerData ec = (GBServerData)handler.getClientData();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String stateTime[] = new String[6];
        stateTime[0] = strs[6];
        stateTime[1] = strs[7];
        stateTime[2] = strs[8];
        stateTime[3] = strs[9];
        stateTime[4] = strs[10];
        stateTime[5] = strs[11];
        String componentState[] = new String[1];
        componentState[0] = strs[4];
        GB268753QN GBQN = new GB268753QN();
        GBQN.setId(ec.getUniqueCode());
        GBQN.setUniqueCode(ec.getUniqueCode());
        GBQN.setUploadTime(sdf.format(new Date()));
        GBQN.setStateTime(dataProcessing.strsToTime(stateTime));
        GBQN.setSysType((new StringBuilder(String.valueOf(dataProcessing.hexStringToInt10(strs[2])))).toString());
        GBQN.setComponentType("");
        GBQN.setIsComponent("1");

        String componentStatestr=componentState[0];
        Object o=redisCache.get(componentStatestr+"-ml4");
        String mapStr="";//状态json串
        if(null!=o){
            mapStr=o.toString();
            Map mapTypes = JSON.parseObject(mapStr);
            GBQN.setComponentStateMap(mapTypes);
        }else {
            Map<String,Object> map=new HashMap<>();
            map.put("hex",componentStatestr);
            map.put("ml",4);
            Gb26875State gb26875State=gb26875StateService.queryByHex(map);
            if(null!=gb26875State){
                mapStr=gb26875State.getBjzt();
                redisCache.set(componentStatestr+"-ml4",mapStr);
                Map mapTypes = JSON.parseObject(mapStr);
                GBQN.setComponentStateMap(mapTypes);
            }else{
                GBQN.setComponentStateMap(QNA2B4State.getQNA2B4State(componentState));
                try{
                    Map<String, String> mapState=QNA2B4State.getQNA2B4State(componentState);
                    String ss = JSON.toJSONString(mapState);
                    Gb26875State gb26875State1=new Gb26875State();
                    gb26875State1.setId(UUIDUtils.get32UUID());
                    gb26875State1.setMl(4);
                    gb26875State1.setBjzt(ss);
                    gb26875State1.setHex(componentStatestr);
                    gb26875StateService.insertStatic(gb26875State1);
                    redisCache.set(componentStatestr+"-ml4",ss);
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
        }

        //GBQN.setComponentStateMap(QNA2B4State.getQNA2B4State(componentState));
        GBQN.setSysAddress((new StringBuilder(String.valueOf(dataProcessing.hexStringToInt10(strs[3])))).toString());
        GBQN.setLoopNumber("");
        GBQN.setComponentNumber("");
        GBQN.setTwiceCode("");
        return GBQN;
    }
}
